package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AppUserLogin;
import com.ruoyi.system.service.IAppUserLoginService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * app用户登录日志Controller
 *
 * @author ruoyi
 * @date 2023-03-02
 */
@RestController
@RequestMapping("/system/login")
public class AppUserLoginController extends BaseController {
    @Autowired
    private IAppUserLoginService appUserLoginService;

    /**
     * 查询app用户登录日志列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AppUserLogin appUserLogin) {
        startPage();
        List<AppUserLogin> list = appUserLoginService.selectAppUserLoginList(appUserLogin);
        return getDataTable(list);
    }

    /**
     * 导出app用户登录日志列表
     */
    @Log(title = "app用户登录日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppUserLogin appUserLogin) {
        List<AppUserLogin> list = appUserLoginService.selectAppUserLoginList(appUserLogin);
        ExcelUtil<AppUserLogin> util = new ExcelUtil<AppUserLogin>(AppUserLogin.class);
        util.exportExcel(response, list, "app用户登录日志数据");
    }

    /**
     * 获取app用户登录日志详细信息
     */
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId) {
        return success(appUserLoginService.selectAppUserLoginByUserId(userId));
    }

    /**
     * 新增app用户登录日志
     */
    @Log(title = "app用户登录日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppUserLogin appUserLogin) {
        return toAjax(appUserLoginService.insertAppUserLogin(appUserLogin));
    }

    /**
     * 修改app用户登录日志
     */
    @Log(title = "app用户登录日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppUserLogin appUserLogin) {
        return toAjax(appUserLoginService.updateAppUserLogin(appUserLogin));
    }

    /**
     * 删除app用户登录日志
     */
    @Log(title = "app用户登录日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds) {
        return toAjax(appUserLoginService.deleteAppUserLoginByUserIds(userIds));
    }
}
